package com.ruoyi.demo.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.demo.domain.vo.SchedulingVo;
import com.ruoyi.demo.domain.bo.SchedulingBo;
import com.ruoyi.demo.service.ISchedulingService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节目排期
 *
 * @author haha
 * @date 2023-03-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/scheduling/scheduling")
public class SchedulingController extends BaseController {

    private final ISchedulingService iSchedulingService;

    /**
     * 查询节目排期列表
     */
    @SaCheckPermission("scheduling:scheduling:list")
    @GetMapping("/list")
    public TableDataInfo<SchedulingVo> list(SchedulingBo bo, PageQuery pageQuery) {
        return iSchedulingService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出节目排期列表
     */
    @SaCheckPermission("scheduling:scheduling:export")
    @Log(title = "节目排期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SchedulingBo bo, HttpServletResponse response) {
        List<SchedulingVo> list = iSchedulingService.queryList(bo);
        ExcelUtil.exportExcel(list, "节目排期", SchedulingVo.class, response);
    }

    /**
     * 获取节目排期详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("scheduling:scheduling:query")
    @GetMapping("/{id}")
    public R<SchedulingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSchedulingService.queryById(id));
    }

    /**
     * 新增节目排期
     */
    @SaCheckPermission("scheduling:scheduling:add")
    @Log(title = "节目排期", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SchedulingBo bo) {
        return toAjax(iSchedulingService.insertByBo(bo));
    }

    /**
     * 修改节目排期
     */
    @SaCheckPermission("scheduling:scheduling:edit")
    @Log(title = "节目排期", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SchedulingBo bo) {
        return toAjax(iSchedulingService.updateByBo(bo));
    }

    /**
     * 删除节目排期
     *
     * @param ids 主键串
     */
    @SaCheckPermission("scheduling:scheduling:remove")
    @Log(title = "节目排期", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSchedulingService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
